home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / libs / sphigs / sph_dos.lha / dos / sphsrc.v08 / sph_attrib.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-11-26  |  2.2 KB  |  79 lines

  1. #include "HEADERS.h"
  2. #include "sphigslocal.h"
  3.  
  4.  
  5.  
  6. /** LOADING A MICROCOLOR INTO THE SPHIGS VIRTUAL COLORTABLE 
  7. Only for loading into the very small microcolor table, excluding the
  8. first two microcolors (0 and 1).
  9. **/
  10.  
  11.  
  12. void SPH_loadCommonColor (int colorindex, char *name)
  13. {
  14.    register i;
  15.    unsigned short  r, g, b;     /* A SHADE OF THE ACTUAL COLOR */
  16.    unsigned short rr,gg,bb;    /* ACTUAL COLOR */
  17.    int basethiscolor;
  18.    double bias;
  19.  
  20.    if ( ! IS_CHANGEABLE_COLOR_INDEX(colorindex))
  21.       return;
  22.  
  23.    SRGP_loadCommonColor (colorindex, name);
  24.    
  25.    if ( ! IS_A_FLEXICOLORINDEX(colorindex))
  26.       return;
  27.       
  28.    /* THE FOLLOWING EXECUTED ONLY IF ACTUAL FLEXICOLOR */
  29.    SRGP_inquireColorTable (colorindex, 1, &rr, &gg, &bb);
  30.  
  31.    basethiscolor = BASE_OF_SHADE_LUT_ENTRIES + 
  32.       (colorindex-2)*NUM_OF_SHADES_PER_FLEXICOLOR;
  33.  
  34.    for (i=0; i<NUM_OF_SHADES_PER_FLEXICOLOR; i++) {
  35.       bias = 
  36.      0.35 + 
  37.         (0.65 * ((double)(i+1) / (double)NUM_OF_SHADES_PER_FLEXICOLOR));
  38.       r = rr * bias;
  39.       g = gg * bias;
  40.       b = bb * bias;
  41.       SRGP_loadColorTable ((basethiscolor+i), 1, &r, &g, &b);
  42.    }
  43. }
  44.  
  45.  
  46.  
  47. extern int srgp__available_depth;
  48.  
  49. void SPH__initColorTable (int shades_per_flexicolor)
  50. {
  51.    register i;
  52.    int num_of_srgp_colors = (1 << SRGP_inquireCanvasDepth());
  53.    
  54. #ifdef THINK_C
  55.    /* On Mac, very highest LUT entry must be reserved and stay black! */
  56.    if (num_of_srgp_colors == (1 << srgp__available_depth))
  57.       num_of_srgp_colors--; 
  58. #endif
  59.    
  60.    /* Compute the number of flexicolors that will be possible */
  61.    /* I assume that C truncates when division is performed. */
  62.    NUM_OF_FLEXICOLORS = 
  63.       (num_of_srgp_colors - 2) / (1 + shades_per_flexicolor);
  64.                
  65.    if (NUM_OF_FLEXICOLORS < 1) {
  66.       NUM_OF_FLEXICOLORS = 0;
  67.       BASE_OF_SHADE_LUT_ENTRIES = num_of_srgp_colors;
  68.    }
  69.    else {
  70.       /* Calculate dependent statistics */
  71.       NUM_OF_SHADES_PER_FLEXICOLOR = shades_per_flexicolor;
  72.       BASE_OF_SHADE_LUT_ENTRIES = 
  73.      num_of_srgp_colors - (NUM_OF_FLEXICOLORS * shades_per_flexicolor);
  74.       /* Load black into all the changeable color-table entries */
  75.       for (i=2; i<BASE_OF_SHADE_LUT_ENTRIES; i++)
  76.           SPH_loadCommonColor (i, "black");
  77.    }
  78. }
  79.